import datetime
from typing import List, Optional
from pydantic import BaseModel, Field, field_validator


class UserBase(BaseModel):
    id: Optional[int] = Field("id", description="id")
    username: Optional[str] = Field("admin", description="用户名")
    password: Optional[str] = Field("123456", description="密码")


# 用户登录
class UserLogin(UserBase):
    pass


# 用户展示信息
class UserShow(UserBase):
    status: int = Field("status", description="状态")
    created_date: datetime.datetime = Field("创建时间", description="创建时间")

    @field_validator('created_date')
    def parse_created_date(cls, v):
        return v.strftime("%Y-%m-%d %H:%M:%S")

    class Config:
        from_attributes = True


class UserUpdateShow(UserBase):
    powers: List[int] = Field([], description="权限")
    status: int = Field("status", description="状态")